<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
  <%include("/common/header.html",{title:''}){}%>
  <title>商品列表</title>
  <link rel="stylesheet" href="css/formSelects-v4.css"/>
</head>
<body>

<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">订单管理</a><span lay-separator="">/</span>
        <a><cite>购物订单</cite></a>
      </span>
  <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
     href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon layui-icon-refresh-3"></i>
  </a>
</div>

<div class="layui-form layui-card-header layuiadmin-card-header-auto">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">审核状态</label>
      <div class="layui-input-block">
        <select type="text" name="status" id="status" autocomplete="off" class="layui-select">
          <option value="">-请选择-</option>
          <option value="0">已通过</option>
          <option value="1">财务审核中</option>
          <option value="2">管理审核中</option>
          <option value="3">未通过</option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
      <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
      </button>
    </div>
  </div>
</div>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
      <script type="text/html" id="toolbarDemo">
        <button class="layui-btn layuiadmin-btn-useradmin" lay-event="add">新增订单</button>
        <!--<button class="layui-btn layuiadmin-btn-useradmin" lay-event="combination">组合商品</button>-->
      </script>

      <script type="text/html" id="table-view-a">
        <a class="layui-btn  layui-btn-xs" lay-event="hutan"><i class="layui-icon layui-icon-form"></i>查看</a>
      </script>
      <script type="text/html" id="imgTpl">
        <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
      </script>
      <script type="text/html" id="table-useradmin-webuser">
        {{#  if(d.status === 1&&d.deletetype===0){ }}
        <div style="color: #0e94ea">财务审核中</div>
        {{#  } }}
        {{#  if(d.status === 2&&d.deletetype===0){ }}
        <div style="color: #0e94ea">管理审核</div>
        {{#  } }}
        {{#  if(d.status === 0&&d.deletetype===0){ }}
        <div style="color: #0e94ea">通过</div>
        {{#  } }}
        {{#  if(d.deletetype===1){ }}
        <div style="color: red">已经撤销</div>
        {{#  } }}
        {{#  if(d.status===3){ }}
        <div style="color: red">已经驳回</div>
        {{#  } }}
      </script>
      <script type="text/html" id="table-useradmin-opt">
        {{#  if(d.status === 1 && d.deletetype==0){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="chexiao"><i
                class="layui-icon layui-icon-refresh-3"></i>撤销订单</a>
        {{#  }else if(d.status === 3  && d.deletetype==0){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="resbon"><i
                class="layui-icon layui-icon-close-fill"></i>驳回原因</a>
        {{#  }else{ }}
        <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="null"><i
                class="layui-icon layui-icon-close-fill"></i>不可操作</a>
        {{#  } }}

      </script>
    </div>
  </div>
</div>


<!--弹出开设账号-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
  <form class="layui-form" action="" lay-filter="component-form-element" id="myform">
    <input type="hidden" name="id">

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
      </div>
    </div>
  </form>
</div>


<div class="layui-form" lay-filter="layuiadmin-form-useradmins"
     id="layuiadmin-form-useradmins"
     style="padding: 15px;display: none">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">*登录账号</label>
      <div class="layui-input-inline">
        <input type="text" name="phone" id="phone" lay-verify="phone" placeholder="请输入账号" class="layui-input" >
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*登录密码</label>
      <div class="layui-input-inline">
        <input type="text" name="passWord" lay-verify="passWord" placeholder="请输入密码" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*用户名称</label>
      <div class="layui-input-inline">
        <input type="text" name="name" lay-verify="name" placeholder="请输入用户名称" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*详细地址</label>
      <div class="layui-input-inline">
        <input type="text" name="address" lay-verify="required" placeholder="请输入用户地址" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*资质性质</label>
      <div class="layui-input-inline">
        <input type="radio" name="isPerson" lay-verify="required" class="layui-input" title="个人" value="0">
        <input type="radio" name="isPerson" lay-verify="required" class="layui-input" title="企业" value="1">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*证件号码</label>
      <div class="layui-input-inline">
        <input type="text" name="idCard" lay-verify="idCard" placeholder="请输入身份证/统一信用代码" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">*联系方式</label>
      <div class="layui-input-inline">
        <input type="text" name="mobile" lay-verify="mobile" placeholder="请输入联系方式" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*开户银行</label>
      <div class="layui-input-inline">
        <input type="text" name="bankName" lay-verify="required" placeholder="请输入开户行名称" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">*银行卡号</label>
      <div class="layui-input-inline">
        <input type="text" name="bankNum" lay-verify="bankNum" placeholder="请输入银行卡号并核实" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"> 电子邮箱</label>
      <div class="layui-input-inline">
        <input type="text" name="email" placeholder="请输入邮箱" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"> 固定电话</label>
      <div class="layui-input-inline">
        <input type="text" name="telePhone" placeholder="请输入固定电话(可选填)" class="layui-input">
      </div>
    </div>


    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">购买商品</label>
        <table class="layui-table" lay-size="lg">
          <colgroup>
            <col width="50">
            <col width="200">
            <col width="30">
            <col width="30">
          </colgroup>
          <thead>
          <tr>
            <th>选择</th>
            <th>名称</th>
            <th>价钱</th>
            <th>数量</th>
          </tr>
          </thead>
          <tbody id="listlist">

          </tbody>
        </table>
        <!--<div class="layui-input-inline">
          <select name="goodId" id="quiz" lay-filter="goodId">
          </select>
        </div>-->
      </div>
    </div>


    <!--

        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">优惠券</label>
            <div class="layui-input-inline">
              <select name="quiz">
                <option value="">请选择问题</option>
                <option value="你工作的第一个城市">优惠券</option>
                <option value="你的工号">代金券</option>
              </select>
            </div>
          </div>

        </div>
    -->


    <!-- <div class="layui-form-item" pane="">
       <label class="layui-form-label">增值服务</label>
       <div class="layui-input-block">
         <input type="checkbox" name="like1[write]" lay-skin="primary" title="全局展示" checked="">
         <input type="checkbox" name="like1[read]" lay-skin="primary" title="人工智能">
       </div>
     </div>-->


    <div class="layui-form-item" style="width: 50%">
      <label class="layui-form-label">价格</label>
      <div class="layui-input-block">
        <input type="text" id="totalPrice" name="totalPrice" value="0" readonly lay-verify="required" placeholder="￥"
               autocomplete="off" class="layui-input">
      </div>
    </div>


    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
      </div>
    </div>
  </form>
</div>
<div class="layui-form" lay-filter="table-huyang"
     id="table-huyang"
     style="padding: 15px;display: none">
  <form class="layui-form" action="" lay-filter="component-form-element-b" id="myform1">
    <div class="layui-form-item">
      <h3 class="layui-form-label">商品信息</h3>
      <table class="layui-table" lay-size="lg">

        <thead>
        <tr>
          <th width="200">名称</th>
          <th width="40">单价</th>
          <th width="30">数量</th>
        </tr>
        </thead>
        <tbody id="yigougoods">

        </tbody>
      </table>
    </div>
  </form>
</div>
<!--
<script id="demo2" type="text/html">
  <option value="">请选择</option>
  {{#  layui.each(d.list, function(index, item){ }}

  <option {{d.goodid== item.id?"selected":""}} value="{{ item.id }}">{{ item.goodName }}</option>

  {{#  }); }}
  {{#  if(d.list.length === 0){ }}
  <option disabled value="">无</option>
  {{#  } }}
</script>
-->

<script id="goods2" type="text/html">
  {{#  layui.each(d.list, function(index, item){ }}
  <tr>
    <td><input type="checkbox" lay-filter="goodId" name="ckgood" value="{{item.id}}" lay-skin="primary" title=""></td>
    <td>{{item.goodName}}</td>
    <td>{{item.price}}</td>
    {{#  if(item.ckbox===0){ }}
    <td>
      <button type="button" class="jian">-</button>
      <input name="goodsnum" style="width: 40px" disabled placeholder="数量" value="0">
      <button class="addnum" type="button">+</button>
    </td>
    {{#  } }}
    {{#  if(item.ckbox===1){ }}
    <td>
      <button type="button" class="jiandis" disabled>-</button>
      <input name="goodsnum" style="width: 40px" disabled placeholder="数量" value="1">
      <button class="addnumdis" type="button" disabled>+</button>
    </td>
    {{#  } }}

  </tr>
  {{#  }); }}
</script>
<script id="edgoods" type="text/html">
  {{#  layui.each(d.list, function(index, item){ }}
  <tr>
    <td>{{item.goods.goodName}}</td>
    <td>{{item.goods.price}}</td>
    <td>{{item.numbers}}</td>
  </tr>
  {{#  }); }}
</script>
<%include("/common/foot.html"){}%>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script src="js/formSelects-v4.js" type="text/javascript" charset="utf-8"></script>
<script>

  layui.use(['index', 'table', 'form', 'laydate', 'layedit', 'AjaxCommon', 'AliangLayui'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var layedit = layui.layedit;
    var AliangLayui = layui.AliangLayui;
    var index;


    //富文本编辑器
    layedit = layui.layedit;

    var title = "驳回意见";
    var size = ['100%', '100%']
    var titles = "订单信息";
    var sizes = ['100%', '100%']
    var findAll_url = 'purchaseorder/list/findallorder.jhtml';
    var update_url = 'purchaseorder/list/update.jhtml';
    var delete_url = 'purchaseorder/list/delete.jhtml';

    var cols = [ //表头
      {field: 'orderNo', title: '订单编号'},
      {field: 'totalPrice', title: '价格'},
      {field: 'buyName', title: '购买用户', templet: "<div>{{d.sysUser.name}}</div>"},
      {field: 'phone', title: '用户联系方式'},
      {field: 'accountname', title: '业务员'},
      {field: 'goodname', title: '购买商品', toolbar: '#table-view-a'},
      {field: 'buyTime', title: '购买时间'},
      {title: '订单状态', toolbar: '#table-useradmin-webuser'},
      {title: '操作', toolbar: '#table-useradmin-opt', fixed: 'right'}
    ];
    AliangLayui.createTable(
      "#LAY-user-manage",
      "listReload",
      "#toolbarDemo",
      title,
      findAll_url,
      true,
      [10, 15, 20, 25],
      ['filter', 'print', 'exports'],
      cols,
      null
    );
    //自定义验证规则
    // form.verify({
    //   required: [/[\S]+/, "必填项不能为空"],
    //
    // });


    var totalArray = new Array();
    //弹出层
    //查看业务员
    function initUpdateBelongTo(data) {
      //console.log(JSON.stringify(data))
      layer.open({
        title: "商品详细信息",
        area: size,
        type: 1,
        content: $('#table-huyang'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
      });

      var laytpl = layui.laytpl;
      var ret2 = { //数据
        "list": data.detailsSet
      };
      laytpl($("#edgoods").html()).render(ret2, function (html) {
        $("#yigougoods").html(html);
      });

      layui.form.val("component-form-element", loadData(data));

    }

    form.on('select(goodId)', function (data1) {
      //alert(JSON.stringify(data1))
      // alert(1)
      $.ajax({
        url: "purchaseorder/list/findgood.jhtml",
        type: "POST",
        data: {
          gid: data1.value
        },
        dataType: "json",
        success: function (ret) {
          // alert(JSON.stringify(ret))
          //  alert(ret.obj.price)
          $("#totalPrice").val(ret.obj.price)
          form.render();
        },
        error: function (jqXHR, textStatus, errorThrown) {
        }
      });
    });
    form.on('checkbox(goodId)', function (data) {
      var pi = $("#totalPrice").val();

      if (data.elem.checked) {
        $("#totalPrice").val(Number(pi) + Number($(data.elem).parent().next().next().text())*Number($(data.elem).parent().next().next().next().children().eq(1).val()));
      } else {
        if ($("#totalPrice").val()!=0){
          $("#totalPrice").val(Number(pi) - Number($(data.elem).parent().next().next().text())*Number($(data.elem).parent().next().next().next().children().eq(1).val()));
        }
      }

      console.log($(data.elem).parent().next().next().text()); //得到checkbox原始DOM对象
      console.log(data.elem.checked); //是否被选中，true或者false
      console.log(data.value); //复选框value值，也可以通过data.elem.value得到
      console.log(data.othis); //得到美化后的DOM对象
    });

    $(document).on('click', '.addnum', function () {
      if ($(this).parent().prev().prev().prev().children().is(':checked')) {
        $(this).prev().val(Number($(this).prev().val()) + 1);
        $("#totalPrice").val(Number($("#totalPrice").val())+Number($(this).parent().prev().text()));
      } else {
        alert("请先勾选此商品！");
      }
      //alert($(this).parent().prev().prev().prev().children().is(':checked'))

    });
    $(document).on('click', '.jian', function () {
      if ($(this).parent().prev().prev().prev().children().is(':checked')) {
        if ($(this).next().val() > 0) {
          $(this).next().val(Number($(this).next().val()) - 1);
          $("#totalPrice").val(Number($("#totalPrice").val())-Number($(this).parent().prev().text()));
        } else {
          $(this).next().val(Number($(this).next().val()));
        }
      } else {
        alert("请先勾选此商品！");
      }
    });

    //初始化修改页面
    function loadData(data) {
      var ret = {
        "id": data.id,
        "business": data.business,
        "goodsName": data.goodsName,
        "money": data.money,
        "brand": data.brand,
        "price": data.price,
        "company": data.company,
        "goodscontent": data.goodscontent
      }
      return ret;
    }

    //时间范围
    laydate.render({
      elem: '#test9'
      , type: 'time'
      , range: true
    });

    //建立编辑器
    index = layedit.build('content', {

      uploadImage: {url: 'system/goods/Img.jhtml', type: 'post'},
      height: 320
    });


    //初始化日期模块
    laydate.render({
      elem: '#create' //指定元素
    });
    //////////////////////////////////////以上是修改每个页面修改的地方
    //弹出修改页面调用初始化数据方法
    function initUpdate(data) {
      layer.open({
        title: title,
        area: size,
        type: 1,
        content: $('#layuiadmin-form-useradmin'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
      });


      layui.form.val("component-form-element", loadData(data));

    }


    function initUpdate(data) {
      layer.open({
        title: title,
        area: size,
        type: 1,
        content: $('#layuiadmin-form-useradmin'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
      });


      layui.form.val("component-form-element", loadData(data));

    }


    var sizeNew = ['900px', '700px'];

    function initUpdates(data) {
      layer.open({
        title: titles,
        area: ['100%', '100%'],
        type: 1,
        content: $('#layuiadmin-form-useradmins'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
      });

      $.ajax({
        url: "purchaseorder/list/find.jhtml",
        type: "POST",
        data: {},
        dataType: "json",
        success: function (ret) {
          //alert(JSON.stringify(ret))
          var laytpl = layui.laytpl;
          var ret2 = { //数据
            "list": ret.obj
          };
          laytpl($("#goods2").html()).render(ret2, function (html) {
            $("#listlist").html(html);
          });
          form.render();
        },
        error: function (jqXHR, textStatus, errorThrown) {
        }
      });

      // layui.form.val("component-form-elements", loadDatas(data));
      form.verify({
        phone: function(value){
          if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
            return '用户名不能有特殊字符';
          }
          if(/(^\_)|(\__)|(\_+$)/.test(value)){
            return '用户名首尾不能出现下划线\'_\'';
          }
          if(/^\d+\d+\d$/.test(value)){
            return '用户名不能全为数字';
          }
          var checkResult = "";
          var checkValue=value.trim();
          $.ajax({
            url: "validate/validateForm.jhtml",
            type: "post",
            data: {
              "phone":checkValue
            },
            async: false,
            success: function(result) {
              // alert(JSON.stringify(result))
              if(result.obj.length>0){
                checkResult = "该账号已存在";
              }
            },
            error: function() {
            }
          });
          return checkResult;
        },
        idCard:function (value) {
          // if(!new RegExp("/(^\\d{15}$)|(^\\d{17}(x|X|\\d)$)/").test(value)){
          //   return '请输入正确的身份证号';
          // }
          var checkResult = "";
          var checkValue=value.trim();
          $.ajax({
            url: "validate/validateIdCard.jhtml",
            type: "post",
            data: {
              "idCard":checkValue
            },
            async: false,
            success: function(result) {
              // alert(JSON.stringify(result))
              if(result.obj.length>0){
                checkResult = "该身份证号已存在";
              }
            },
            error: function() {
            }
          });
          return checkResult;
        },
        mobile:function(value){
          // if(!new RegExp("/^1\\d{10}$/").test(value)){
          //   return '请输入正确的手机号';
          // }
          var checkResult = "";
          var checkValue=value.trim();
          $.ajax({
            url: "validate/validateMobile.jhtml",
            type: "post",
            data: {
              "mobile":checkValue
            },
            async: false,
            success: function(result) {
              // alert(JSON.stringify(result))
              if(result.obj.length>0){
                checkResult = "该手机号码已存在";
              }
            },
            error: function() {
            }
          });
          return checkResult;
        },
        bankNum:function (value) {
          var checkResult = "";
          var checkValue=value.trim();
          $.ajax({
            url: "validate/validateBankNum.jhtml",
            type: "post",
            data: {
              "bankNum":checkValue
            },
            async: false,
            success: function(result) {
              // alert(JSON.stringify(result))
              if(result.obj.length>0){
                checkResult = "请换一张银行卡";
              }
            },
            error: function() {
            }
          });
          return checkResult;
        },
        required: [/[\S]+/, "必填项不能为空"]
      });
    }


    //修改页面的内容提交到后台处理
    form.on('submit(component-form-element)', function (data) {
      // alert(1)
      //data.field.content = layedit.getContent(index);
      postUpdate(data);
      return false;
    });
    //头工具栏事件
    table.on('toolbar(LAY-user-manage)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      switch (obj.event) {
        case 'add':
          initUpdates(0);
          break;
        case 'combination':
          initUpdates(0);
          break;
        case 'export':
          layer.msg("导出");
          break;
      }
    });

    //点击每行右工具栏“操作”里面按钮效果
    table.on('tool(LAY-user-manage)', function (obj) {
      var data = obj.data;
      if (obj.event === 'detail') {
        layer.msg('ID：' + data.id + ' 的查看操作');
      } else if (obj.event === 'hutan') {
        initUpdateBelongTo(data)
      } else if (obj.event === 'edit') {

        layer.msg("审核通过")


      } else if (obj.event === 'del') {
        initUpdate(data);
        // layer.confirm('删除以后数据将不能恢复，确定删除吗？', function (index) {
        //     //alert(data.id);
        //     postDelete(data.id);
        // });
      } else if (obj.event === 'chexiao') {
        //询问框
        layer.confirm('敏感操作，你是否需要撤销订单？', {
          btn: ['确认', '取消'] //按钮
        }, function () {
          //alert(JSON.stringify(obj))
          $.ajax({
            url: delete_url,
            type: "POST",
            data: {
              "id": obj.data.id
            },
            dataType: "json",
            success: function (ret) {
              if (ret == null) {
                layer.msg("撤销失败", {
                  icon: 5
                });
              } else {
                layer.msg("撤销成功", {
                  icon: 6
                });
                layer.closeAll();
                table.reload('listReload');
              }
              return ret;
            },
            error: function (jqXHR, textStatus, errorThrown) {
              var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
              layer.open({
                title: "错误信息",
                area: ['600px', '600px'],
                type: 2,
                content: "base/error.jhtml?info=" + estr, //
                btn: ['关闭'] //可以无限个按钮
              });
            }
          });
        }, function () {
          /* layer.msg('也可以这样', {
             time: 20000, //20s后自动关闭
             btn: ['明白了', '知道了']
           });*/
        });

      } else if (obj.event === 'resbon') {
        layer.open({
          type: 1,
          title: false
          //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
          ,content: '<div style="padding: 20px 100px;">'+ obj.data.reason1 +'</div>'
          ,btn: '关闭'
          ,btnAlign: 'c' //按钮居中
          ,shade: 0 //不显示遮罩
          ,yes: function(){
            layer.closeAll();
          }
        });

      }
    });


    //监听搜索按钮效果
    form.on('submit(LAY-user-front-search)', function (data) {

      var field = data.field;
      // alert(JSON.stringify(field))
      table.reload('listReload', {
        where: {
          status: field.status,
        },
        page: {
          curr: 1
        }
      });
    });
    //ajax提交修改内容
    window.postUpdate = function (data) {
      //console.log(data)
      var formData = new FormData();
      formData.append("data", JSON.stringify(data.field));

      var arr = new Array();
      var arrgoods = new Array()
      $("input:checkbox[name='ckgood']:checked").each(function (i) {
        arr[i] = $(this).val();
        //alert()
        arrgoods[i] = $(this).parent().next().next().next().children().eq(1).val()
      });
      formData.append("goods", arr);
      formData.append("numbers", arrgoods);
      //alert(JSON.stringify(arr))
      $.ajax({
        url: update_url,
        type: "POST",
        //traditional:true,
        data: formData,
        processData: false,
        contentType: false,
        success: function (data) {
          if (data.code == 0) {
            layer.closeAll();
            layer.msg(data.msg, {time: 600, icon: 1}, function () {
              //table.reload('listReload');
              location.replace(location.href);
            });
          } else {
            layer.msg(data.msg, {icon: 5});
          }
        },
        error: function (jqXHR, textStatus, errorThrown) {
          var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
          layer.open({
            title: "错误信息",
            type: 2,
            content: "base/error.jhtml?info=" + estr,
            btn: ['关闭'] //可以无限个按钮
          });
        }
      });
    }
    //ajax提交删除内容
    window.postDelete = function (id) {
      $.ajax({
        url: delete_url,
        type: "POST",
        data: {
          "id": id
        },
        dataType: "json",
        success: function (ret) {
          if (ret == null) {
            layer.msg("删除失败", {
              icon: 5
            });
          } else {
            layer.msg("删除成功", {
              icon: 6
            });
            layer.closeAll();
            table.reload('listReload');
          }
          return ret;
        },
        error: function (jqXHR, textStatus, errorThrown) {
          var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
          layer.open({
            title: "错误信息",
            area: ['600px', '600px'],
            type: 2,
            content: "base/error.jhtml?info=" + estr, //
            btn: ['关闭'] //可以无限个按钮
          });
        }
      });
    }


  });

</script>
</body>

</html>
